#include "../Basics/BasicStruct.cpp"



// 二插搜索树 查找一个值为key的节点
// 左孩子小,右孩子大
/*
  *       5
  *      / \
  *     1   7
  *        / \
  *       6   8
  * */

TreeNode* FindKey(TreeNode* bt,int key) {
    TreeNode* p = bt;
    while(p != NULL && p->data != key) {
        if (p->data < key) {
            p = p->rightChild;
        }else {
            p = p->leftChild;
        }
    }

    return p;
}


int main() {
    /*
   *       5
   *      / \
   *     1   7
   *        / \
   *       6   8
   * */
   Tree tree = CreateSearchTree();
   TreeNode* result = FindKey(tree,8);
   printf("%d",result->data);
}
